package fr.xebia.view;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;
import com.opensymphony.xwork2.ValidationAwareSupport;

import fr.xebia.service.ServiceLocator;

/**
 * 
 */
public abstract class GenericAction extends ValidationAwareSupport implements ServletRequestAware, Preparable {

	private static final long serialVersionUID = 1L;

	protected ServiceLocator serviceLocator = ServiceLocator.getInstance();
	protected Logger logger = Logger.getLogger(getClass());
	protected HttpServletRequest request;

	/**
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void prepare() throws Exception {
	}

	/**
	 * @param string
	 * @param e
	 * @return
	 */
	protected String handleError(String message, Exception e) {
		addActionError(message + ": " + e.getMessage());
		logger.error(message, e);
		return Action.ERROR;
	}
}
